home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2002 November / SGI IRIX 6.5 Applications 2002 November.iso / dist / gateway.idb / usr / WebFace / Tasks / security-end.cgi.z / security-end.cgi
Encoding:
Text File  |  2002-06-12  |  11.3 KB  |  407 lines

  1. #!/usr/bin/perl5
  2. #
  3. # security-end.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: security-end.cgi,v 1.16 1998/06/17 18:16:13 shotes Exp $
  21.  
  22. require "/usr/OnRamp/lib/OnRamp.pm";
  23.  
  24. if (!$ARGV[0]) { printf("Location: %s%c%c","/tasks/Tasks.security-start.cgi",10,10); exit; } 
  25.  
  26. $myname = "security-end.cgi?" . $ARGV[0];
  27. $inet_conf = "/etc/inetd.conf";
  28. $snmp_auth = "/etc/snmpd.auth";
  29. $passwd = "/etc/passwd";
  30. $temp = "task.tmp";
  31. $pwtemp = "task.tmp2";
  32. $rltemp = "task.tmp3";
  33. $nmtemp = "task.tmp4";
  34. $dummy = "task.dummy";
  35.  
  36. $it = "<td colspan=60>";
  37. $ni = "</td>";
  38. $bo = "<td colspan=150><font size=5><i>";
  39. $nb = "</i></font></td>";
  40.  
  41. @daemons = ('telnet','login','shell','ftp','finger');
  42.  
  43. &get_fields;
  44. &readValues;
  45.  
  46. if ($fld{'cancel'}) { 
  47.     $message = "Security changes cancelled"; 
  48. } elsif ($fld{'accept'}) {
  49.     $done = 1;
  50.     system ("rm", "-f", $temp) if (-e "$temp");
  51.     system ("rm", "-f", $pwtemp) if (-e "$pwtemp");
  52.     system ("rm", "-f", $rltemp) if (-e "$rltemp");
  53.     system ("rm", "-f", $nmtemp) if (-e "$nmtemp");
  54.     &generic;
  55.     &configure;
  56.  
  57.     exit 0;
  58. }
  59.  
  60. &generic;
  61.  
  62. sub configure {
  63.     if ($all_inetd) {
  64.     &comment_all_inetd;
  65.     uncomment($inet_conf,*enable);
  66.     }
  67.     foreach $arg (keys %accounts) {
  68.         if ($accounts{$arg} eq "close") { 
  69.             push(@toclose,$arg); 
  70.             delete $accounts{$arg};
  71.         }
  72.     }
  73.     if ($#toclose >= 0) { &star(*toclose); } 
  74.     &addPasswords;
  75.     system("/etc/killall", "-HUP", "inetd");
  76.     &configure_rlogin;
  77.     &configure_snmp;
  78. }
  79.  
  80. sub star {
  81.     local(*names) = $_[0];
  82.     open(IN, "< $passwd");
  83.     open(OUT, ">  $temp");
  84.     while(<IN>) {
  85.         $print = 1;
  86.         $line = $_;
  87.         @items = split(/:/, $line);
  88.         foreach (@names) {
  89.             if ($items[0] eq $_) {
  90.                 $items[1] = "*";
  91.                 print OUT join(":", @items);
  92.                 $print = 0;
  93.             }
  94.         }
  95.         if ($print) { print OUT $line; }
  96.     }
  97.     close(IN);
  98.     close(OUT);
  99.     rename($temp, $passwd);
  100. }
  101.  
  102. sub configure_rlogin {
  103.     open(IN, "< $rltemp");
  104.     while(<IN>) {
  105.         ($a, $b) = split(/:/);
  106.         chop $b;
  107.         $rlog{$a} = $b;
  108.     }
  109.     close(IN);
  110.  
  111.     if ($rlog{'rlogin'} eq "yes") {
  112.         if (-e "/etc/hosts.equiv") {
  113.             rename("/etc/hosts.equiv", "/etc/hosts.equiv.gsav");
  114.         }
  115.         opendir(DIR, "/usr/people");
  116.         @accts = grep(!/^\.\.?$/, readdir(DIR));
  117.         closedir(DIR);
  118.         foreach $acct (@accts) {    
  119.             $fname = "/usr/people/" . $acct . "/.rhosts";
  120.             $nfname = $fname . ".gsav";
  121.             if (-e $fname) { rename($fname, $nfname); }
  122.         }
  123.     }
  124.  
  125.     if ($rlog{'xhost'} eq "yes") {
  126.         $ENV{'DISPLAY'} = ":0";
  127.         system("/usr/bin/X11/xhost - > /dev/null");
  128.     }
  129. }
  130.  
  131. sub configure_snmp {
  132.     open(IN, "< $nmtemp");
  133.     while(<IN>) {
  134.         ($a, $b) = split(/:/);
  135.         chop $b;
  136.         $snmp{$a} = $b;
  137.     }
  138.     close(IN);
  139.  
  140.     if ($snmp{'get'} eq "yes" || $snmp{'set'} eq "yes") {
  141.         open(OUT, ">  $dummy");
  142.  
  143.         open(IN, "< $snmp_auth");
  144.         while(<IN>) {
  145.             $line = $_;
  146.             if (($line eq "\n") || ($line =~ /^\#/)) { print OUT $line; next; }
  147.         else { print OUT "# $line"; }
  148.         }
  149.         close(IN);
  150.  
  151.         print OUT "reject  *:*/set\n" if ($snmp{'set'} eq "yes");
  152.         print OUT "reject  *:*/get\n" if ($snmp{'get'} eq "yes");
  153.         close(OUT);
  154.         rename($dummy,$snmp_auth);
  155.     }
  156.  
  157.     if ($snmp{'daemon'} eq "yes") {
  158.         system("/etc/chkconfig", "snmpd", "off");
  159.         system("/etc/killall", "snmpd");
  160.     } else {
  161.         system("/etc/killall", "-HUP", "snmpd");
  162.     }
  163. }
  164.  
  165. sub readValues {
  166.     open(IN,"< $temp");
  167.     while(<IN>) {
  168.         chop;
  169.         $on{$_} = 1;
  170.     }
  171.     close(IN);
  172.     
  173.     if ($on{"all_inetd"}) { $all_inetd = 1; } else { $all_inetd = 0; }
  174.  
  175.     if ($all_inetd) {
  176.     foreach $arg (@daemons) {
  177.         if ($on{$arg}) { push(@enable, $arg); }
  178.     }
  179.     }
  180.  
  181.     open(IN,"< $pwtemp");
  182.     while(<IN>) {
  183.         @items = split(/=/);
  184.         chop $items[1];
  185.     $items[0] =~ s/DASH/-/g;
  186.         $accounts{$items[0]} = $items[1];
  187.     }
  188.     close(IN);
  189.  
  190.     open(IN, "< $rltemp");
  191.     while(<IN>) {
  192.         ($a, $b) = split(/:/);
  193.         chop $b;
  194.         $rlog{$a} = $b;
  195.     }
  196.     close(IN);
  197.  
  198.     open(IN, "< $nmtemp");
  199.     while(<IN>) {
  200.         ($a, $b) = split(/:/);
  201.         chop $b;
  202.         $snmp{$a} = $b;
  203.     }
  204.     close(IN);
  205. }
  206.  
  207. sub generic {
  208.     print "Content-type: text/html\n\n";
  209.     print "<html><head><title>Summary</title>\n";
  210.         print "<script language=\"JavaScript\">\n<!--\n";
  211.  
  212.     # JavaScript
  213. print "which = \"none\";
  214. function runSubmit() {
  215.     if(which == \"accept\") return (true);
  216.     if(which == \"cancel\") return runCancel();
  217.     return (true);
  218. }
  219. function markAccept() { which = \"accept\"; }
  220. function markCancel() { which = \"cancel\"; }
  221. function runCancel()  {
  222.     setTimeout('window.location=\"/tasks/Tasks.security-start.cgi?end\"',0);
  223.     return (false);
  224. }
  225. function Previous()  {
  226.     setTimeout('window.location=\"/tasks/security-fourth.cgi?end\"',0);
  227.     return;
  228. }\n";
  229.  
  230.     print "//-->\n";
  231.     print "</script></head>\n\n";
  232.  
  233.  
  234.     print "<body bgcolor='a7b4ce' background=/tasks/security-task.bg.gif>\n";
  235.  
  236.     print "<i>$message</i>";
  237.  
  238.     print "<table width=100%>",
  239.           "<tr><th align=left><h1>Summary</h1></th>\n",
  240.           "<th align=right><a href=\"/newsplash.shtml\">",
  241.           "<img height=55 width=57 border=0 src=/tasks/home.gif></a>\n",
  242.           "  <a href=\"/tasks/Tasks.shtml\">",
  243.           "<img height=55 width=57 border=0 src=/tasks/back.gif></a>",
  244.           "</tr></table>\n";
  245.  
  246.     if ($done) {        
  247.         print qq|<center><br><br><br><br><font size=5>\n|;
  248.         print qq|<i>Your security setup has been reconfigured.</i>\n|;
  249.         print qq|</font></center></body></html>\n|;
  250.         return 0;
  251.     }
  252.  
  253. print "<br>
  254. Review the information that you entered in the Security configuration
  255. forms:<br><br>\n\n";
  256.  
  257.     print "<center><table width=500>\n";
  258.  
  259.     print "<tr valign=top><td><b>Disabled services:</b></td><td colspan=2><tt>";
  260.     if ($all_inetd) {
  261.     if ($#enable > -1) {
  262.         print "all except: ";
  263.             foreach $arg (@enable) { print "$arg "; }
  264.     } else { print "all"; }
  265.     } else { print "none"; }
  266.     print "</tt></td></tr><tr><td></td></tr>\n";
  267.  
  268.     print "<tr><td><b>Open accounts:</b></td><td><tt>\n";
  269.     foreach $arg (keys %accounts) { 
  270.         $printed = 1;
  271.         if ($accounts{$arg} eq "close") { 
  272.             print "$arg</tt></td><td><tt>will be closed\n";
  273.         }
  274.         else { print "$arg</tt></td><td><tt>will be password protected\n"; }
  275.         print "</td></tr><tr><td></td><td><tt>\n";
  276.     }
  277.     if (! $printed) {print "<no changes>\n";}
  278.     print "</tt></td></tr>\n";
  279.  
  280.     print "<tr valign=top><td><b>Remote access: </b></td><td colspan=2><tt>";
  281.     if ($rlog{'rlogin'} eq "yes") { 
  282.         print "Remote logins will be restricted.<br>"; 
  283.     }
  284.     else { print "Remote logins will not be restricted.<br>"; }
  285.     if ($rlog{'xhost'} eq "yes") { 
  286.         print "Remote access to X server will be restricted."; 
  287.     }
  288.     else { print "Remote access to X server will not be restricted."; }
  289.     print "</tt></td></tr><tr><td></td></tr>\n"; 
  290.  
  291.     print "<tr valign=top><td><b>Network management: </b></td><td colspan=2><tt>";
  292.     if ($snmp{'set'} eq "yes") { 
  293.         print "SNMP write access will be restricted.<br>"; 
  294.     }
  295.     else { print "SNMP write access will not be restricted.<br>"; }
  296.     if ($snmp{'get'} eq "yes") { 
  297.         print "SNMP write access will be restricted.<br>"; 
  298.     }
  299.     else { print "SNMP write access will not be restricted.<br>"; }
  300.     if ($snmp{'daemon'} eq "yes") { 
  301.         print "SNMP daemon will be disabled."; 
  302.     }
  303.     else { print "SNMP daemon will not be disabled."; }
  304.     print "</tt></td></tr><tr><td></td></tr>\n"; 
  305.  
  306.     print "</table></center><br><br>\n\n";
  307.     printf("<form name=\"end\" action=\"%s\" method=post onSubmit=\"return runSubmit()\">\n", $myname);
  308.  
  309.     print "<center><table><tr><td width=80%>";
  310.     print "If your entries are correct, select <var>Accept</var>
  311.         to configure the Internet Gateway server with the information
  312.         shown above.";
  313.     print "</td><td valign=top align=right>";
  314.     print "<font size=5><i>\n";
  315.     print qq|<input type=submit name="accept" value="Accept"
  316.         onClick="markAccept()">\n|;
  317.     print "</i></font>\n\n";
  318.  
  319.     print "</td></tr><tr><td width=80%>";
  320.  
  321.     print "If you see an error in your entries, select <var>Cancel</var> to
  322.            delay the configuration and return to the beginning of the security 
  323.            forms to correct your entries. If you prefer, you can select 
  324.            <var>Previous</var> to return to the previous form.";
  325.     print "</td><td valign=top align=right>";
  326.     print qq|<font size=5><i><input type=submit name="cancel" value="Cancel"
  327.         onClick="markCancel()">\n|;
  328.     print "</i></font>\n\n";
  329.     print "</td></tr></table></center><br>";
  330.  
  331.     print '<MAP NAME="js_map1">',
  332.     '    <AREA SHAPE="rect" COORDS="0,0,59,52" HREF="javascript:Previous()">',
  333.     '</MAP>',
  334.     '<IMG SRC="/tasks/leftarrow.gif" BORDER=0 USEMAP="#js_map1" ALIGN="right">';
  335.  
  336.     print "\n</form></body></html>";
  337. }
  338.  
  339. # this will only uncomment the first instance of each daemon 
  340. sub uncomment {
  341.     local($file) = $_[0];
  342.     local(*values) = @_[1];
  343.     open(IN,"< $file");
  344.     open(OUT,"> $dummy");
  345.  
  346.     while(<IN>) {
  347.         $line = $_;
  348.         if (($line eq "\n") || ($line !~ /^\s*\#/)) { print OUT $line; next; }
  349.         $line =~ /^\s*\#\s*(\S.*)/;
  350.         $line1 = $1;
  351.         @items = split(/\s+/,$line1);
  352.         $found = 0;
  353.         for ($ii=0;$ii<=$#values;$ii++) {
  354.             if ($items[0] eq $values[$ii]) { 
  355.                 if (! $done{$items[0]}) {
  356.                     $found = 1; 
  357.                     $done{$items[0]} = 1; 
  358.                     last; 
  359.                 }
  360.             }
  361.         }
  362.         if ($found) { print OUT "$line1\n"; }
  363.         else { print OUT $line; }
  364.     }
  365.     close(OUT);
  366.     close(IN);
  367.     rename($dummy,$file);
  368. }
  369.  
  370. sub comment_all_inetd {
  371.     local($file) = $inet_conf;
  372.     open(IN,"< $file");
  373.     open(OUT,"> $dummy");
  374.  
  375.     while(<IN>) {
  376.         $line = $_;
  377.         if (($line eq "\n") || ($line =~ /^\#/)) { print OUT $line; next; }
  378.     else { print OUT "# $line"; }
  379.     }
  380.     close(OUT);
  381.     close(IN);
  382.     rename($dummy,$file);
  383. }
  384.  
  385. sub addPasswords {
  386.     foreach $arg (keys %accounts) {
  387.         $salt = mksalt();
  388.         $passwords{$arg} = crypt($accounts{$arg}, $salt);
  389.     }
  390.  
  391.     open(PSWD, "< $passwd");
  392.     open(TMP, "> $dummy");
  393.     while (<PSWD>) {
  394.         $line = $_;
  395.         @ents = split(/:/, $line);
  396.         if ($passwords{$ents[0]}) {
  397.             $ents[1] = $passwords{$ents[0]};
  398.             print TMP join(':', @ents);
  399.             next;
  400.         }
  401.         print TMP $line;
  402.     }
  403.     close(TMP);
  404.     close(PSWD);
  405.     rename($dummy, $passwd);
  406. }
  407.